// pages/miaoku/miaokudetail/miaokudetail.js
var utils = require("../../../utils/utils.js");
const app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        currentObj:{
            currentColor:1,
            currentNum:1,
            currentFace:1,
            currentPaper:'30523606',
          },
          docFixShow:false,   //设置文档view
          num:1,
          refreshState:false,
          page:1,
          pageNum:10,
          key:'',
          currentPrice:0.00,
          isFree:0,
          sxFixShow:false,
          nextType:'',
          firstOpen:0
    },
    getIndex(){
        var that = this;
        var data = {
            id:that.data.id
        }
        utils.request('Index/tempDetail', data, function (res) {
          if(res.data.code==1){
            that.setData({
                list:res.data.data
            })
          }else{
            utils.toast(res.data.msg)
          }
        })
    },
        //设置个空白方法，阻止冒泡
        touchAnother(){

        },
      //打开文档设置
  showDocFix(e){
    var id = e.currentTarget.dataset.id;
      var obj = this.data.currentObj
      obj.code = e.currentTarget.dataset.id;
      this.setData({
        docFixShow:true,
        currentObj:obj
      })
  },
  preview(e){
    var that = this;
    var url = e.currentTarget.dataset.url;
    var title = e.currentTarget.dataset.title;
    if(utils.is_define(url)){
      if(that.data.firstOpen==0){
        wx.showModal({
          title: '预览提示',
          content:'预览为有水印版，正式打印为无水印版',
          showCancel:false,
          confirmText:'我知道了',
          success(res) {
            that.setData({
              firstOpen:1
            })
            wx.hideLoading()
            wx.navigateTo({
                url: '/pages/my/pdfsee/pdfsee?url='+url+'&name='+title
            })
          }
        })
      }else{
        wx.navigateTo({
            url: '/pages/my/pdfsee/pdfsee?url='+url+'&name='+title
        })
      }
    }else{
      utils.toast('当前文档暂不支持预览')
    }
  },
  addCart(){
    var that = this;
    var obj = that.data.currentObj;
    app.get_local('AccToken').then(res =>{
      if(utils.is_define(res)){
        app.get_local('machineQrCode').then(res => {
          if(utils.is_define(res)){
            wx.showLoading()
            var data = {
              tempId:obj.code,
              num:obj.currentNum,
              paper:obj.currentPaper,
              isColor:obj.currentColor,
              isDouble:obj.currentFace,
              sn:res
            }
            utils.request('Order/tempPrint',data, function (res) {
              wx.hideLoading();
              that.setData({
                docFixShow:false
              })
              if(res.data.code==1){
                wx.navigateTo({
                  url: '/pages/print/list/list',
                })
              }else{
                utils.toast(res.data.msg)
              }
            })
          }else{
            utils.toast("请先选择打印机");
          }
        })
      }else{
        wx.navigateTo({
          url: '/pages/my/login/login',
        })
      }
    })
  },
  //关闭文档设置
  hideDocFix(){
    this.setData({
      docFixShow:false
    })
  },
    // 数量变化
    add() {
        var num = this.data.currentObj.currentNum;
        num++;
        var obj = this.data.currentObj;
        obj.currentNum = num;
        this.setData({
          currentObj:obj
        })
      },
      lessen() {
        var num = this.data.currentObj.currentNum;
        if (num == 1) {
          utils.toast('最小份数为1')
          return false;
        }
        num--;
        var obj = this.data.currentObj;
        obj.currentNum = num;
        this.setData({
          currentObj:obj
        })
      },
      //单双面
      changeFace(e){
        var index = e.currentTarget.dataset.index;
        var obj = this.data.currentObj;
        obj.currentFace = index;
        this.setData({
          currentObj:obj
        })
      },
      //色彩
      changeColor(e){
        var index = e.currentTarget.dataset.index;
        var obj = this.data.currentObj;
        obj.currentColor = index;
        this.setData({
          currentObj:obj
        })
      },
      // 纸张
      changePaper(e){
        var index = e.currentTarget.dataset.index;
        var obj = this.data.currentObj;
        obj.currentPaper = index;
        this.setData({
          currentObj:obj
        })
      },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        var that = this;
        that.setData({
            id:options.code
        })
        wx.setNavigationBarTitle({
          title:options.name,
        })
        that.getIndex()
        wx.getSystemInfo({
            success: (result) => {
                var model = result.model;
                if(model=='iPhone X'){
                    that.setData({
                    pdbottom:'68',
                    })
                }else{
                that.setData({
                    pdbottom:'40'
                })
                }
            },
            })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    }
})